﻿<%@ Page Title="Authoring Tool" Language="C#" MasterPageFile="~/quickLMS.master" AutoEventWireup="true" CodeFile="AuthTool.aspx.cs" Inherits="Admin_AuthTool" ValidateRequest="false" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <table cellspacing="0" cellpadding="5">
        <tr>
            <td id="ResourceTab" style="background-color: #eeeeee; border-left: 1px solid black; border-top: 1px solid black;">
                <a style="cursor: hand; cursor: pointer;" onclick="SelectTable(2)">Resources</a>
            </td>
            <td id="FolderTab" style="background-color: #eeeeee; border-left: 1px solid black; border-top: 1px solid black;">
                <a style="cursor: hand; cursor: pointer;" onclick="SelectTable(1)">Folders</a>
            </td>
            <td id="BuildTab" style="background-color: #eeeeee; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black;" onclick="SelectTable(3)">
                <a style="cursor: hand; cursor: pointer;" onclick="SelectTable(3)">Build</a>
            </td>
            <td id="Td1">
                <a style="cursor: hand; cursor: pointer; color: Blue;" onclick="OpenHelpPopup()">Help</a>
            </td>
        </tr>
    </table>
    <table id="FolderTable" style="width:95%; background-color: #f5f5f5; border: 1px solid black;">
        <tr>
            <td style="width: 100%;" colspan="2">
                (Hold right mouse button and drag resource to folder to associate)
                (Left click folder for context menu)
            </td>
        </tr>
        <tr>
            <td style="width: 50%;">
                Folders:
                <div id="FolderTree" style="background-color: White; border: 1px solid black; padding: 5px; width: 500px; height: 250px; overflow-y: scroll;"></div>
                <input type="button" id="btnMoveUp" value="Move Up" onclick="MoveFolder(-1)" /><input type="button" id="btnMoveDown" value="Move Down" onclick="MoveFolder(1)" />
            </td>
            <td style="width: 50%;">
                Resources:
                <div id="FolderResources" style="background-color: White; border: 1px solid black; padding: 5px; width: 500px; height: 250px; overflow-y: scroll;"></div>
            </td>
        </tr>
    </table>
    <table id="ResourceTable" style="width:51%; background: #f5f5f5; border: 1px solid black;">
        <tr>
            <td>
                Resource Name:
            </td>
            <td>
                <input type="text" id="txtResourceName" size="50" />
            </td>
        </tr>
        <tr>
            <td>
                Resource Type:
            </td>
            <td>
                <asp:DropDownList ID="ddlResourceTypes" runat="server" DataValueField="TypeName" DataTextField="CommonName"></asp:DropDownList><div id="divAssessmentUpload" style="display: none;"><input type="checkbox" id="cbAssessmentUpload" onchange="CheckAssessmentUpload(this)" > Upload Assessment</div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <div id="WLPanel" style="display: none;">
                    Web Link Location:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="text" id="txtWebLinkLoc" />
                </div>
                <div id="DTPanel" style="display: none;">
                    Forum Text:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="text" id="txtForumText" size="80" />
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" id="btnAddResource" value="Add Resource" onclick="AddResource()" >
            </td>
            <td>
                <input type="button" id="btnDeleteResource" value="Delete Resource" onclick="DeleteResource(1)" />
                <input type="button" id="btnRenameResource" value="Rename Resource" onclick="RenameResource()" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                Resources:
                <div id="ResourceList" style="background-color: White; border: 1px solid black; padding: 5px; overflow-y: scroll; height: 120px;"></div>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <table id="FileTable">
                    <tr>
                        <td>
                            File:
                        </td>
                        <td>
                            <iframe id="ifrm" name="iFile" src="FileUpload.aspx?CourseID=<%= CourseID %>" style="width: 100%; height: 30px; border: 0px;"></iframe>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <table id="FileButtonTable">
                    <tr>
                        <td>
                            <input type="button" id="btnAddFile" value="Add File to Resource" onclick="AddFile()" />
                        </td>
                        <td>
                            <input type="button" id="btnSetHref" value="Set As Main Resource File" onclick="SetHref()" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <div id="FileList" style="background-color: White; border: 1px solid black; padding: 5px;"></div>
            </td>
        </tr>
    </table>
    <table id="BuildTable" style="width:51%; background: #f5f5f5; border: 1px solid black;">
        <tr>
            <td>
                <iframe id="BuildFrame" name="bFrame" src="Build.aspx?CourseID=<%= CourseID %>" style="border: 0px; height: 200px;"></iframe>
            </td>
        </tr>
    </table>
    <br />
    <div id="XML" style="border: 1px solid black; background-color: #f5f5f5; width: 50%; visibility: hidden;"></div>
    <div id="AssessmentPanel" style="position: absolute; top: 90px; left: 50px; width: 90%; height: 500px; border: 1px solid black; background-color: #f5f5f5; display: none; z-index: 1;">
        <table width="100%">
            <tr>
                <td>
                    Assessment Name:
                </td>
                <td>
                    <input type="text" id="AssessmentName" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="button" id="btnAddQuestion" value="Add Question" onclick="AddQuestion()" />
                </td>
                <td>
                    <input type="button" id="btnCreateAssessment" value="Done" onclick="CreateAssessment(1)" />
                    <input type="button" id="btnCancelAssessment" value="Cancel" onclick="CreateAssessment(0)" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <hr />
                    <div id="RenderQuestions">
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div id="AssessmentQuestionPanel" style="position: absolute; top: 130px; left: 100px; width: 80%; height: 500px; border: 1px solid black; background-color: #f5f5f5; display: none; z-index: 2;">
        <table width="100%">
            <tr>
                <td>
                    Question Title:
                </td>
                <td>
                    <input type="text" id="AssessmentQuestionTitle" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    Question Text:
                </td>
                <td>
                    <input type="text" id="AssessmentQuestionText" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    Question Type:
                </td>
                <td>
                    <select id="ddlQuestionType" onchange="CheckQuestionType(this)">
                        <option value="cc.multiple_choice.v0p1">Multiple Choice Single Answer</option>
                        <option value="cc.fib.v0p1">Fill in the Blank</option>
                        <option value="cc.multiple_response.v0p1">Multiple Choice Multiple Answer</option>
                        <option value="cc.true_false.v0p1">True False</option>
                        <option value="cc.pattern_match.v0p1">Pattern Match</option>
                        <option value="cc.essay.v0p1">Essay</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="button" id="btnAddAnswer" value="Add Answer" onclick="AddAnswer()" />
                </td>
                <td>
                    <input type="button" id="btnAddFeedback" value="Add Feedback" onclick="AddFeedback()" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="button" id="btnCreateQuestion" value="Done" onclick="CreateQuestion(1)" />
                </td>
                <td>
                    <input type="button" id="btnCancelQuestion" value="Cancel" onclick="CreateQuestion(0)" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <hr />
                    <div id="RenderAnswers">
                    </div>
                    <hr />
                    <div id="RenderFeedbacks">
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div id="AnswerPanel" style="position: absolute; top: 160px; left: 150px; width: 50%; border: 1px solid black; background-color: #f5f5f5; display: none; z-index: 3;">
        <table width="100%">
            <tr>
                <td>
                    Answer Text:
                </td>
                <td>
                    <input type="text" id="AnswerText" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    Correct Answer:
                </td>
                <td>
                    <input type="checkbox" id="cbCorrectAnswer" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="button" id="btnAddAnswerDone" value="Done" onclick="CreateAnswer(1)" />
                </td>
                <td>
                    <input type="button" id="btnAddAnswerCancel" value="Cancel" onclick="CreateAnswer(0)" />
                </td>
            </tr>
        </table>
    </div>
    <div id="FeedbackPanel" style="position: absolute; top: 160px; left: 150px; width: 50%; border: 1px solid black; background-color: #f5f5f5; display: none; z-index: 3;">
        <table width="100%">
            <tr>
                <td>
                    Feedback Text:
                </td>
                <td>
                    <input type="text" id="FeedbackText" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="button" id="btnFeedbackDone" value="Done" onclick="CreateFeedback(1)" />
                </td>
                <td>
                    <input type="button" id="btnFeedbackCanel" value="Cancel" onclick="CreateFeedback(0)" />
                </td>
            </tr>
        </table>
    </div>
    <div id="LtiPanel" style="position: absolute; top: 160px; left: 150px; width: 70%; border: 1px solid black; background-color: #f5f5f5; display: none; z-index: 1;">
        <table width="100%">
            <tr>
                <td>
                    Courses on this site: (Leave Blank to Manually Enter a Launch URL and Tool ID)
                </td>
                <td>
                    <asp:DropDownList ID="ddlCourses" runat="server" DataTextField="CourseName" DataValueField="CourseID" Width="80%">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    Launch URL:
                </td>
                <td>
                    <input type="text" id="txtLaunchURL" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    Tool ID:
                </td>
                <td>
                    <input type="text" id="txtToolID" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    Tool Title:
                </td>
                <td>
                    <input type="text" id="txtToolTitle" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    Organization:
                </td>
                <td>
                    <input type="text" id="txtOrgTitle" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    Organization Url:
                </td>
                <td>
                    <input type="text" id="txtVendorUrl" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    Organization Email:
                </td>
                <td>
                    <input type="text" id="txtVendorEmail" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="button" id="btnCreateLTI" value="Done" onclick="CreateLTI(1)" />
                </td>
                <td>
                    <input type="button" id="btnCancelLTI" value="Cancel" onclick="CreateLTI(0)" />
                </td>
            </tr>
        </table>
    </div>
    <div id="ContextMenu" style="position: absolute; width: 200px; background-color: #f1f1f1; display: none; border: 1px solid black; padding: 10px; z-index: 3;">
        <div id="ContextFolderName" style="font-size: 12pt;"></div><br />
        <div style="background-color: #f9f9f9; border: 1px solid black;">
            <div style="cursor: hand; cursor: pointer;" onmouseover="this.style.backgroundColor = '#cccccc'" onmouseout="this.style.backgroundColor = '#f9f9f9'" onclick="OpenAddChild()">Add Child Folder</div>
            <div style="cursor: hand; cursor: pointer;" onmouseover="this.style.backgroundColor = '#cccccc'" onmouseout="this.style.backgroundColor = '#f9f9f9'" onclick="OpenEditFolder()">Rename Folder</div>
            <div style="cursor: hand; cursor: pointer;" onmouseover="this.style.backgroundColor = '#cccccc'" onmouseout="this.style.backgroundColor = '#f9f9f9'" onclick="DeleteFolder()">Delete Folder</div>
            <div style="cursor: hand; cursor: pointer;" onmouseover="this.style.backgroundColor = '#cccccc'" onmouseout="this.style.backgroundColor = '#f9f9f9'" onclick="SetResource(2)">Disassociate Resource</div>
        </div>
    </div>
    <div id="ResourceMenu" style="position: absolute; width: 400px; background-color: #f5f5f5; display: none; border: 1px solid black; padding: 10px; z-index: 3;">
        Select the resource to associate with this folder:<br /><br />
        <input type="button" onclick="SelectFResource(-1)" value="Disassociate Resource" /><br /><br />
        <div id="OBSOLETEFolderResources" style="background-color: White; border: 1px solid black; padding: 5px;"></div>
    </div>
    <div id="GrayOut" style="background-color: #eeeeee; opacity: .5; filter: alpha(opacity = '50'); position: absolute; left: -10px; top: -300px; display: none;">
    </div>
    <div id="ContextDisable" style="background-color: #eeeeee; opacity: .0; filter: alpha(opacity = '0'); position: absolute; left: -10px; top: -300px; display: none; z-index: 2;" onclick="HideContextMenu()" onContextMenu="return HideContextMenu()">
    </div>
    <div id="FloatingPanel" style="font-size: 12pt; border: 1px solid black; padding: 10px; background-color: #eeeeee; opacity: .75; filter: alpha(opacity = '75'); position: absolute; display: none; z-index: 3; cursor: hand; cursor: pointer; text-align: center;">Test</div>
    <div id="AddFolderPanel" style="position: absolute; width: 400px; background-color: #f5f5f5; display: none; border: 1px solid black; padding: 10px; z-index: 3;">
        <table>
            <tr>
                <td>
                    Folder Name:
                </td>
                <td>
                    <input type="text" id="txtFolderName" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="button" value="Done" onclick="AddFolder(1)" />
                </td>
                <td>
                    <input type="button" value="Cancel" onclick="AddFolder(2)" />
                </td>
            </tr>
        </table>
    </div>
    <div id="EditFolderPanel" style="position: absolute; width: 400px; background-color: #f5f5f5; display: none; border: 1px solid black; padding: 10px; z-index: 3;">
        <table>
            <tr>
                <td>
                    Folder Name:
                </td>
                <td>
                    <input type="text" id="txtEditFolderName" size="50" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="button" value="Done" onclick="EditFolder(1)" />
                </td>
                <td>
                    <input type="button" value="Cancel" onclick="EditFolder(2)" />
                </td>
            </tr>
        </table>
    </div>
    <div id="HelpPopup" style="position: absolute; width: 900px; height: 400px; left: 100px; top: 100px; background-color: #efefef; border: 1px solid black; display: none; padding: 5px;">
        <a onclick="CloseHelpPopup()" style="color: Blue; cursor: pointer; cursor: hand;">Close</a>
        <br /><br />
        <table cellpadding="10">
            <tr>
                <td>
                    1) Add a resource to a cartridge by naming it, selecting its type, and selecting add resource.
                </td>
            </tr>
            <tr>
                <td>
                    2) Web Content is uploaded from file on your computer.  You add files by selecting them and clicking add file to resource.  You then must set the main file clicking the set as main file button.  The main file is the file you want the cource launcher to open.
                </td>
            </tr>
            <tr>
                <td>
                    3) Assessments can also be uploaded by checking the upload box after selecting the assessment resource type.
                </td>
            </tr>
            <tr>
                <td>
                    4) LTI can use your own end point or one of the cartridges on this system.
                </td>
            </tr>
            <tr>
                <td>
                    5) After adding resources, you must add folders by clicking the folder tab.
                </td>
            </tr>
            <tr>
                <td>
                    6) Folders can be added by clicking on an existing folder or root if none exist and selecting "add child folder".
                </td>
            </tr>
            <tr>
                <td>
                    7) To add a resource to a folder, hold right click and drag the resource onto the folder.
                </td>
            </tr>
            <tr>
                <td>
                    8) After the cartridge is complete, click the build tab and select either update manifest to update an existing one, or export cartridge to download the .zip file.
                </td>
            </tr>
        </table>
    </div>
    
    <script language="javascript" type="text/javascript">
        var Guid = "<%= guid %>";
        var Folders = new Array();
        var Resources = new Array();
        var Assessments = new Array();
        
        var CAssessment = null;
        var CQuestion = null;
        var CAnswer = null;
        var CFeedback = null;

        var CQuestionI = 0;
        var CAnswerI = 0;
        var CFeedbackI = 0;

        var MBPressed = false;
        
        var qt = String.fromCharCode(34);
        Folders.push(new Folder("Root", 0));
        
        var CurrentFolder = 0;
        var CurrentResource = 0;
        var CurrentFResource = -1;
        var CurrentFile = 0;

        MakeTree();
        SelectTable(2);

        document.getElementById("<%= ddlResourceTypes.ClientID %>").selectedIndex = 0;
        document.getElementById("GrayOut").style.height = screen.height + 200 + "px";
        document.getElementById("GrayOut").style.width = screen.width + "px";

        document.getElementById("ContextDisable").style.height = screen.height + "px";
        document.getElementById("ContextDisable").style.width = screen.width - 20 + "px";

        ParseManifest();
        
        function Folder(name, level, index, parent)
        {
            this.Name = name;
            this.Level = level;
            this.IdRef = "";
            this.Index = index;
            this.Parent = parent;
        }

        function Resource(name, type)
        {
            this.Name = name;
            this.Type = type;
            this.Href = "";
            this.Files = new Array();
        }
        
        function Assessment()
        {
            this.Name = "";
            this.Questions = new Array();
        }
        
        function Question()
        {
            this.Title = "";
            this.Text = "";
            this.Type = "";
            this.TypeText = "";
            this.Answers = new Array();
            this.Feedbacks = new Array();
        }
        
        function Answer()
        {
            this.Text = "";
            this.Score = 0;
            this.FRef = new Array();
        }
        
        function Feedback()
        {
            this.Text = "";
        }

        function MakeTree()
        {
            var i = 0;
            var z = 0;
            document.getElementById("FolderTree").innerHTML = "";
            while (i < Folders.length)
            {
                if (i == CurrentFolder)
                {
                    if (Folders[i].IdRef != "")
                    {
                        document.getElementById("FolderTree").innerHTML += "<a title='" + Folders[i].IdRef + "' style='font-size: 12pt; cursor: hand; cursor: pointer; color: blue; background-color: #dddddd; margin: " + Folders[i].Level * 20 + "px' onContextMenu = 'return SelectFolder(" + i + ")' onclick='OpenContextMenu(" + i + ")'><img src='file.gif'>" + Folders[i].Name + "</a><br>";
                        document.getElementById("FolderTree").innerHTML += "<a style='color: #000000; margin: " + (Folders[i].Level + 1) * 20 + "px'>" + Folders[i].IdRef + "</a><br>";
                    }
                    else
                        document.getElementById("FolderTree").innerHTML += "<a title='" + Folders[i].IdRef + "' style='font-size: 12pt; cursor: hand; cursor: pointer; color: blue; background-color: #dddddd; margin: " + Folders[i].Level * 20 + "px' onContextMenu = 'return SelectFolder(" + i + ")' onclick='OpenContextMenu(" + i + ")'><img src='folder.gif'>" + Folders[i].Name + "</a><br>";
                }
                else
                {
                    if (Folders[i].IdRef != "")
                    {
                        document.getElementById("FolderTree").innerHTML += "<a title='" + Folders[i].IdRef + "' style='font-size: 10pt; cursor: hand; cursor: pointer; color: blue; margin: " + Folders[i].Level * 20 + "px' onContextMenu = 'return SelectFolder(" + i + ")' onclick='OpenContextMenu(" + i + ")'><img src='file.gif'>" + Folders[i].Name + "</a><br>";
                        document.getElementById("FolderTree").innerHTML += "<a style='color: #000000;; margin: " + (Folders[i].Level + 1) * 20 + "px'>" + Folders[i].IdRef + "</a><br>";
                    }
                    else
                        document.getElementById("FolderTree").innerHTML += "<a title='" + Folders[i].IdRef + "' style='font-size: 10pt; cursor: hand; cursor: pointer; color: blue; margin: " + Folders[i].Level * 20 + "px' onContextMenu = 'return SelectFolder(" + i + ")' onclick='OpenContextMenu(" + i + ")'><img src='folder.gif'>" + Folders[i].Name + "</a><br>";
                }
                i++;
            }
            //MakeXML();
        }
        
        function MakeXML()
        {
            var i = 0;
            document.getElementById("XML").innerHTML = "&lt;?xml version=" + qt + "1.0" + qt + " encoding=" + qt + "UTF-8" + qt + " ?&gt;<br><br>";
            //document.getElementById("XML").innerHTML += "&lt;organizations&gt;<br>&lt;organization&gt;<br>";
            while(i < Folders.length)
            {
                if(Folders[i].IdRef != "")
                    document.getElementById("XML").innerHTML += "<a style='margin: " + Folders[i].Level * 20 + "px'>&lt;item identifier=" + qt + "Folder-" + i + qt + " identifierref=" + qt + Folders[i].IdRef + qt + "&gt;</a><br>";
                else
                    document.getElementById("XML").innerHTML += "<a style='margin: " + Folders[i].Level * 20 + "px'>&lt;item identifier=" + qt + "Folder-" + i + qt + "&gt;</a><br>";
                document.getElementById("XML").innerHTML += "<a style='margin: " + (Folders[i].Level + 1) * 20 + "px'>&lt;title&gt;" + Folders[i].Name + "&lt;/title&gt;</a><br>";

                if (i != Folders.length - 1)
                {
                    if (Folders[i].Level >= Folders[i + 1].Level)
                        document.getElementById("XML").innerHTML += "<a style='margin: " + Folders[i].Level * 20 + "px'>&lt;/item&gt;</a><br>";
                } else
                {
                    z = Folders[i].Level;
                    while (z >= 0)
                    {
                        document.getElementById("XML").innerHTML += "<a style='margin: " + z * 20 + "px'>&lt;/item&gt;</a><br>";
                        z--;
                    }
                }
                i++;
            }
            //document.getElementById("XML").innerHTML += "&lt;/organizations&gt;<br>&lt;/organization&gt;<br>";
            document.getElementById("XML").innerHTML += "<br>";
            i = 0;
            while (i < Resources.length)
            {
                var z = 0;
                document.getElementById("XML").innerHTML += "&lt;resource identifier=" + qt + Resources[i].Name + qt + " type=" + qt + Resources[i].Type + qt + " href=" + qt + Resources[i].Href + qt + "&gt;<br>";
                while (z < Resources[i].Files.length)
                {
                    document.getElementById("XML").innerHTML += "<a style='margin: 20px;'>&lt;file href=" + qt + Resources[i].Files[z] + qt + " /&gt;<br>";
                    z++;
                }
                document.getElementById("XML").innerHTML += "&lt;/resource&gt;<br>";
                i++;
            }
        }
        
        function MakeManifest()
        {
            var i = 0;
            var hxml = frames["bFrame"].document.getElementById("hidXML");
            frames["bFrame"].document.getElementById("hidGuid").value = "<%= guid %>";
            
            hxml.value = "";
            hxml.value += "<organizations>\n<organization>\n";
            while (i < Folders.length)
            {
                if (Folders[i].IdRef != "")
                    hxml.value += "<item identifier=\"Folder-" + i + "\" identifierref=\"" + Folders[i].IdRef + "\">\n";
                else
                    hxml.value += "<item identifier=\"Folder-" + i + "\">\n";
                hxml.value += "<title>" + Folders[i].Name + "</title>\n";

                if (i != Folders.length - 1)
                {
                    z = Folders[i].Level;
                    while(z >= Folders[i + 1].Level)
                    {
                        hxml.value += "</item>\n";
                        z--;
                    }
                } else
                {
                    z = Folders[i].Level;
                    while (z >= 0)
                    {
                        hxml.value += "</item>\n";
                        z--;
                    }
                }
                i++;
            }
            hxml.value += "</organization>\n</organizations>\n\n<resources>\n";
            
            i = 0;
            while (i < Resources.length)
            {
                var z = 0;
                hxml.value += "<resource identifier=\"" + Resources[i].Name + "\" type=\"" + Resources[i].Type + "\" href=\"" + Resources[i].Href + "\">\n";
                while (z < Resources[i].Files.length)
                {
                    hxml.value += "<file href=\"" + Resources[i].Files[z] + "\" />\n";
                    z++;
                }
                hxml.value += "</resource>\n";
                i++;
            }

            hxml.value += "</resources>";
        }

        function SelectFolder(n)
        {
            //CurrentFolder = n;
            Folders[n].IdRef = Resources[CurrentFResource].Name;
            document.getElementById("FloatingPanel").style.display = "none";
            MakeTree();
            return false;
        }
        
        function OpenContextMenu(n)
        {
            CurrentFolder = n;
            MakeTree();
            document.getElementById("ContextMenu").style.left = Folders[n].Level * 10 + 50 + "px";
            document.getElementById("ContextMenu").style.top = n * 10 + 140 + "px";
            document.getElementById("ContextMenu").style.display = "block";

            document.getElementById("ResourceMenu").style.left = Folders[n].Level * 10 + 50 + "px";
            document.getElementById("ResourceMenu").style.top = n * 10 + 140 + "px";

            document.getElementById("EditFolderPanel").style.left = Folders[n].Level * 10 + 50 + "px";
            document.getElementById("EditFolderPanel").style.top = n * 10 + 140 + "px";
            
            document.getElementById("ContextDisable").style.display = "block";
            document.getElementById("ContextFolderName").innerHTML = Folders[n].Name;
            return false;
        }
        
        function MoveFolder(dir)
        {
            var i = CurrentFolder + dir;
            var n = CurrentFolder;
            var tf;
            var cf = Folders[n];
            var co = false;
            while (i >= 0 && i < Folders.length)
            {
                if(Folders[i].Level == Folders[n].Level)
                {
                    tf = Folders[i];
                    Folders[i] = Folders[n];
                    Folders[n] = tf;
                    co = true;
                    break;
                }

                if (Folders[i].Level < Folders[n].Level)
                    break;

                i += dir;
            }
            
            if (!co)
                return;

            i = Folders.length - 1;
            n = 0;

            var TempFolders = new Array();
            var PFolders = 0;
            var Level = 0;
            TempFolders.push(Folders[0]);

            while (PFolders < Folders.length - 1)
            {
                while (i >= 0)
                {
                    while (n < TempFolders.length)
                    {
                        if (Folders[i].Parent == TempFolders[n].Index && TempFolders[n].Level == Level)
                        {
                            TempFolders.splice(n + 1, 0, Folders[i])
                            PFolders++;
                        }
                        n++;
                    }
                    n = 0;
                    i--;
                }
                Level++;
                i = Folders.length - 1;
            }

            Folders = TempFolders;

            i = 0;
            while (i < Folders.length)
            {
                if (Folders[i].Index == cf.Index)
                    break;
                i++;
            }

            CurrentFolder = i;
            MakeTree();
        }
        
        function SelectResource(n)
        {
            CurrentResource = n;
            CurrentFile = 0;
            SetResourcePanelsDisplay(Resources[n].Type);
            DisplayResources();
            DisplayFiles();
        }

        function SelectFResource(n, e)
        {
            CurrentFResource = n;
            document.getElementById("FRes" + n).style.backgroundColor = "#dddddd";
            if (e.pageX)
            {
                document.getElementById("FloatingPanel").style.left = e.pageX + 10 + "px";
                document.getElementById("FloatingPanel").style.top = e.pageY + 10 + "px";
            } 
            else
            {
                document.getElementById("FloatingPanel").style.left = e.clientX - document.body.clientLeft + 10 + "px";
                document.getElementById("FloatingPanel").style.top = e.clientY - document.body.clientTop + 10 + "px";
            }
            document.getElementById("FloatingPanel").style.display = "block";
            document.getElementById("FloatingPanel").innerHTML = GetIcon(Resources[n].Type) + "<br>" + Resources[n].Name;
            //document.getElementById("ContextDisable").style.display = "block";
            MBPressed = true;
            return false;
        }
        
        function UnsetMB()
        {
            MBPressed = false;
            document.getElementById("FloatingPanel").style.display = "none";
            if(document.getElementById("FRes" + CurrentFResource) != null)
                document.getElementById("FRes" + CurrentFResource).style.backgroundColor = "#ffffff";
        }
        
        function MoveResource(e)
        {
            if (MBPressed)
            {
                if (e.pageX)
                {
                    document.getElementById("FloatingPanel").style.left = e.pageX + 10 + "px";
                    document.getElementById("FloatingPanel").style.top = e.pageY + 10 + "px";
                }
                else
                {
                    document.getElementById("FloatingPanel").style.left = e.clientX - document.body.clientLeft + 10 + "px";
                    document.getElementById("FloatingPanel").style.top = e.clientY - document.body.clientTop + 10 + "px";
                }
            }
        }
        
        function HideContextMenu()
        {
            document.getElementById("ContextMenu").style.display = "none";
            document.getElementById("ContextDisable").style.display = "none";
            document.getElementById("ResourceMenu").style.display = "none";
            return false;
        }
        
        function OpenAddChild()
        {
            document.getElementById("AddFolderPanel").style.left =  10 + 50 + "px";
            document.getElementById("AddFolderPanel").style.top = 10 + 140 + "px";
            document.getElementById("AddFolderPanel").style.display = "block";
            document.getElementById("GrayOut").style.zIndex = 2;
            document.getElementById("GrayOut").style.display = "block";
            HideContextMenu();
        }

        function AddFolder(opt)
        {
            if (opt == 2)
            {
                document.getElementById("GrayOut").style.display = "none";
                document.getElementById("AddFolderPanel").style.display = "none";
                return;
            }
                
            if (document.getElementById("txtFolderName").value == "")
            {
                alert("Please enter a folder name first");
                return;
            }
            
            document.getElementById("GrayOut").style.display = "none";
            document.getElementById("AddFolderPanel").style.display = "none";
            

            
            var folder = Folders[CurrentFolder];
            var i = CurrentFolder + 1;
            while (i < Folders.length && Folders[i].Level >= folder.Level + 1)
                i++;
            Folders.splice(i, 0, new Folder(document.getElementById("txtFolderName").value, folder.Level + 1, Folders.length + 1, folder.Index));
            MakeTree();
        }

        function EditFolder(opt)
        {
            document.getElementById("GrayOut").style.display = "none";
            document.getElementById("EditFolderPanel").style.display = "none";
            
            if (opt == 2)
                return;

            Folders[CurrentFolder].Name = document.getElementById("txtEditFolderName").value;
            MakeTree();
            HideContextMenu();
        }
        
        function OpenEditFolder()
        {
            document.getElementById("txtEditFolderName").value = Folders[CurrentFolder].Name;
            document.getElementById("GrayOut").style.display = "block";
            document.getElementById("GrayOut").style.zIndex = 2;
            document.getElementById("EditFolderPanel").style.display = "block";
        }
        
        function OpenResourceMenu()
        {
            document.getElementById("ResourceMenu").style.display = "block";
            document.getElementById("ContextDisable").style.display = "block";
        }
        
        function DeleteFolder()
        {
            if (CurrentFolder == 0)
            {
                alert("Root folder can not be deleted");
                return;
            }
            if (confirm("Are you sure you want to delete this folder?"))
            {
                Folders.splice(CurrentFolder, 1);
                CurrentFolder = 0;
                MakeTree();
                HideContextMenu();
                //MakeXML();
            }
        }
        
        function AddResource()
        {
            var RName = document.getElementById("txtResourceName").value;
            if (RName == "")
            {
                alert("Please enter a resource name");
                return;
            }
            
            var rt = document.getElementById("<%= ddlResourceTypes.ClientID %>").value;

            Resources.push(new Resource(RName, rt));
            CurrentResource = Resources.length - 1;
            DisplayResources();

            if (rt == "imsqti_xmlv1p2/imscc_xmlv1p0/assessment" && !document.getElementById("cbAssessmentUpload").checked)
            {
                document.getElementById("AssessmentPanel").style.display = "block";
                document.getElementById("AssessmentName").value = RName;
                CAssessment = new Assessment();
                SetGrayOut(0);
                FocusButons(3);
            }

            if (rt == "imsblti_v1p0")
            {
                document.getElementById("LtiPanel").style.display = "block";
                document.getElementById("<%= ddlCourses.ClientID %>").selectedIndex = 0;
                document.getElementById("txtLaunchURL").disabled = false;
                document.getElementById("txtToolID").disabled = false;
                SetGrayOut(0);
                FocusButons(7);
            }

            if (rt == "imswl_xmlv1p0")
            {
                frames["iFile"].document.getElementById("hidGuid").value = Guid;
                frames["iFile"].document.getElementById("hidFolder").value = Resources[CurrentResource].Name;
                frames["iFile"].document.getElementById("hidXML").value = "<wl:webLink xmlns:wl=\"http://www.imsglobal.org/xsd/imswl_v1p0\">\n<title>" + RName + "</title>\n<url href=\"http://" + document.getElementById("txtWebLinkLoc").value + "\"/>\n</wl:webLink>";
                frames["iFile"].document.getElementById("hidFileName").value = "WebLink.xml";
                frames["iFile"].document.getElementById("btnMakeXMLFile").click();
                Resources[CurrentResource].Href = Resources[CurrentResource].Name + "/" + "WebLink.xml";
                Resources[CurrentResource].Files.push(Resources[CurrentResource].Name + "/" + "WebLink.xml");
            }
            
            if(rt == "imsdt_xmlv1p0")
            {
                frames["iFile"].document.getElementById("hidGuid").value = Guid;
                frames["iFile"].document.getElementById("hidFolder").value = Resources[CurrentResource].Name;
                frames["iFile"].document.getElementById("hidXML").value = "<dt:topic xmlns:dt=\"http://www.imsglobal.org/xsd/imsdt_v1p0\">\n<title>" + RName + "</title>\n<text texttype=\"text/html\">" + document.getElementById("txtForumText").value + "</text></dt:topic>";
                frames["iFile"].document.getElementById("hidFileName").value = "Discussion.xml";
                frames["iFile"].document.getElementById("btnMakeXMLFile").click();
                Resources[CurrentResource].Href = Resources[CurrentResource].Name + "/" + "Discussion.xml";
                Resources[CurrentResource].Files.push(Resources[CurrentResource].Name + "/" + "Discussion.xml");
            }

            DisplayResources();
            //MakeXML();
        }
        
        function AddFile()
        {
            var FName = frames["iFile"].document.getElementById("filUpload").value;
            FName = FName.substring(FName.lastIndexOf('\\') + 1, FName.length);

            frames["iFile"].document.getElementById("hidGuid").value = Guid;
            frames["iFile"].document.getElementById("hidFolder").value = Resources[CurrentResource].Name;
            frames["iFile"].document.getElementById("btnUpload").click();

            Resources[CurrentResource].Files.push(Resources[CurrentResource].Name + "/" + FName);
            if (document.getElementById("<%= ddlResourceTypes.ClientID %>").value == "imsqti_xmlv1p2/imscc_xmlv1p0/assessment")
                Resources[CurrentResource].Href = Resources[CurrentResource].Name + "/Assessment.xml";
            DisplayFiles();
            //MakeXML();
        }
        
        function SetHref()
        {
            Resources[CurrentResource].Href = Resources[CurrentResource].Files[CurrentFile];
            DisplayResources();
            //MakeXML();
        }
        
        function GetIcon(RType)
        {
            if (RType == "imsqti_xmlv1p2/imscc_xmlv1p0/assessment")
                return "<img src='assessment.gif'>";
            else if (RType == "imswl_xmlv1p0")
                return "<img src='weblink.gif'>";
            else if (RType == "imsdt_xmlv1p0t")
                return "<img src='forum.gif'>";
            else if (RType == "imstiptdd_xmlv1p0")
                return "<img src='lti.gif>";
            else if (RType == "webcontent")
                return "<img src='webcontent.gif'>";
            else
                return "<img src='unknown.gif'>";
        }
        
        function DisplayResources()
        {
            var i = 0;
            var icon = "";
            document.getElementById("ResourceList").innerHTML = "";
            document.getElementById("FolderResources").innerHTML = "";
            
            while(i < Resources.length)
            {
                icon = GetIcon(Resources[i].Type);
                if(i != CurrentResource)
                    document.getElementById("ResourceList").innerHTML += "<a id='FRes" + i + "' title='" + Resources[i].Href + "' style='font-size: 10pt; cursor: hand; cursor: pointer; color: blue;' onclick='SelectResource(" + i + ")'>" + icon + Resources[i].Name + "</a><br>";
                else
                    document.getElementById("ResourceList").innerHTML += "<a id='FRes" + i + "' title='" + Resources[i].Href + "' style='font-size: 10pt; cursor: hand; cursor: pointer; color: blue; background-color: #cccccc;' onclick='SelectResource(" + i + ")'>" + icon + Resources[i].Name + "</a><br>";
                if(i != CurrentFResource)
                    document.getElementById("FolderResources").innerHTML += "<a id='FRes" + i + "' title='" + Resources[i].Href + "' style='font-size: 10pt; cursor: hand; cursor: pointer; color: blue;' onmousedown='SelectFResource(" + i + ", event)'>" + icon + Resources[i].Name + "</a><br>";
                else
                    document.getElementById("FolderResources").innerHTML += "<a id='FRes" + i + "' title='" + Resources[i].Href + "' style='font-size: 10pt; cursor: hand; cursor: pointer; color: blue; background-color: #cccccc;' onmousedown='SelectFResource(" + i + ", event)'>" + icon + Resources[i].Name + "</a><br>";
                i++;
            }
            //document.getElementById("btnAddResource").focus();
        }
        
        function DisplayFiles()
        {
            var i = 0;
            document.getElementById("FileList").innerHTML = "";
            while (i < Resources[CurrentResource].Files.length)
            {
                if (i != CurrentFile)
                    document.getElementById("FileList").innerHTML += "<a style='cursor: hand; cursor: pointer; color: blue;' onclick='SelectResource(" + i + ")'>" + Resources[CurrentResource].Files[i] + "</a><br>";
                else
                    document.getElementById("FileList").innerHTML += "<a style='cursor: hand; cursor: pointer; color: blue; background-color: #cccccc;' onclick='SelectResource(" + i + ")'>" + Resources[CurrentResource].Files[i] + "</a><br>";
                i++;
            }
        }
        
        function SetResource(opt)
        {
            if (opt == 1)
                Folders[CurrentFolder].IdRef = Resources[CurrentFResource].Name;
            if (opt == 2)
                Folders[CurrentFolder].IdRef = "";
            HideContextMenu();
            MakeTree();
        }
        
        function DeleteResource(opt)
        {
            if(opt == 1)
            {
                if (confirm("Are you sure you want to delete this resource?"))
                {
                    Resources.splice(CurrentResource, 1);
                    CurrentResource = 0;
                    DisplayResources();
                    //MakeXML();
                }
            } else
            {
                Resources.splice(CurrentResource, 1);
                CurrentResource = 0;
                DisplayResources();
                //MakeXML();
            }
        }
        
        function RenameResource()
        {
            Resources[CurrentResource].Name = document.getElementById("txtResourceName").value;
            DisplayResources();
            //MakeXML();
        }
        
        function ChangeResourceType(obj)
        {
            SetResourcePanelsDisplay(obj.value);
        }
        
        function CheckAssessmentUpload(obj)
        {
            if (obj.checked == true)
            {
                document.getElementById("FileTable").style.visibility = "visible";
                document.getElementById("FileButtonTable").style.display = "block";
            }
            else
            {
                document.getElementById("FileTable").style.visibility = "hidden";
                document.getElementById("FileButtonTable").style.display = "none";
            }
        }
        
        function SetResourcePanelsDisplay(val)
        {
            document.getElementById("divAssessmentUpload").style.display = "none";
            if (val == "imswl_xmlv1p0") 
            {
                document.getElementById("WLPanel").style.display = "block";
                document.getElementById("FileTable").style.visibility = "hidden";
                document.getElementById("DTPanel").style.display = "none";
                document.getElementById("FileButtonTable").style.display = "none";
            }
            else if (val == "imsqti_xmlv1p2/imscc_xmlv1p0/assessment") 
            {
                document.getElementById("WLPanel").style.display = "none";
                document.getElementById("FileTable").style.visibility = "hidden";
                document.getElementById("DTPanel").style.display = "none";
                document.getElementById("FileButtonTable").style.display = "none";
                document.getElementById("divAssessmentUpload").style.display = "block";
                document.getElementById("cbAssessmentUpload").checked = false;
                document.getElementById("btnSetHref").style.display = "none";
                document.getElementById("btnAddFile").value = "Upload Assessment";
            }
            else if (val == "imsdt_xmlv1p0") 
            {
                document.getElementById("WLPanel").style.display = "none";
                document.getElementById("FileTable").style.visibility = "hidden";
                document.getElementById("DTPanel").style.display = "block";
                document.getElementById("FileButtonTable").style.display = "none";
            }
            else if (val == "imstiptdd_xmlv1p0") 
            {
                document.getElementById("WLPanel").style.display = "none";
                document.getElementById("FileTable").style.visibility = "hidden";
                document.getElementById("DTPanel").style.display = "none";
                document.getElementById("FileButtonTable").style.display = "none";
            }
            else 
            {
                document.getElementById("WLPanel").style.display = "none";
                document.getElementById("FileTable").style.visibility = "visible";
                document.getElementById("DTPanel").style.display = "none";
                document.getElementById("FileButtonTable").style.display = "block";
                document.getElementById("btnSetHref").style.display = "block";
                document.getElementById("btnAddFile").value = "Add File to Resource";
            }
        }

        function CreateAssessment(opt)
        {
            document.getElementById("AssessmentPanel").style.display = "none";
            document.getElementById("RenderQuestions").innerHTML = "";
            
            SetGrayOut(-1);
            if (opt == 0)
            {
                DeleteResource(2);
                return;
            }

            CAssessment.Name = document.getElementById("AssessmentName").value;
            
            var AXML = "<questestinterop xmlns=\"http://www.imsglobal.org/xsd/ims_qtiasiv1p2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n";
            AXML += "<assessment ident=\"QDB_1\" title=\"" + CAssessment.Name + "\">\n";
            AXML += "<section ident=\"s1\">\n";

            var i = 0;
            var z = 0;
            var y = 0;
            
            while (i < CAssessment.Questions.length)
            {
                AXML += "<item ident=\"Q-" + i + "\" title=\"" + CAssessment.Questions[i].Title + "\">\n";
                AXML += "<itemmetadata>\n<qtimetadata>\n<qtimetadatafield>\n";
                AXML += "<fieldlabel>cc_profile</fieldlabel>\n";
                AXML += "<fieldentry>" + CAssessment.Questions[i].Type + "</fieldentry>\n";
                AXML += "</qtimetadatafield>\n</qtimetadata>\n</itemmetadata>\n<presentation>\n<material>\n";
                AXML += "<mattext texttype=\"text/html\">" + CAssessment.Questions[i].Text + "</mattext>\n";
                AXML += "</material><response_lid ident=\"Q" + i + "\" rcardinality=\"Single\">\n";
                AXML += "<render_choice>";
                
                z = 0;
                while(z < CAssessment.Questions[i].Answers.length)
                {
                    AXML += "<response_label ident=\"A-" + z + "\">\n";
                    AXML += "<material>\n";
                    AXML += "<mattext texttype=\"text/html\">" + CAssessment.Questions[i].Answers[z].Text + "</mattext>\n";
                    AXML += "</material>\n";
                    AXML += "</response_label>\n"
                    z++;
                }
                AXML += "</render_choice>\n</response_lid>\n\</presentation>\n<resprocessing>\n";
                AXML += "<outcomes><decvar minvalue=\"0\" maxvalue=\"100\" varname=\"SCORE\" vartype=\"Decimal\" />\n";
                AXML += "</outcomes>\n";
                
                z = 0;
                while(z < CAssessment.Questions[i].Answers.length)
                {
                    AXML += "<respcondition>\n<conditionvar>\n";
                    AXML += "<varequal respident=\"A-" + z + "\">A-" + z + "</varequal>\n";
                    AXML += "</conditionvar>\n";
                    AXML += "<setvar action=\"Set\" varname=\"SCORE\">" + CAssessment.Questions[i].Answers[z].Score + "</setvar>";
                    y = 0;
                    while (y < CAssessment.Questions[i].Answers[z].FRef.length)
                    {
                        AXML += "<displayfeedback feedbacktype=\"Response\" linkrefid=\"" + CAssessment.Questions[i].Answers[z].FRef[y] + "\" />\n";
                        y++;
                    }
                    AXML += "</respcondition>\n";
                    z++;
                }
                AXML += "</resprocessing>\n";
                z = 0;
                while(z < CAssessment.Questions[i].Feedbacks.length)
                {
                    AXML += "<itemfeedback ident=\"FID-" + z + "\">\n";
                    AXML += "<flow_mat>\n<material>\n<mattext texttype=\"text/html\">\n";
                    AXML += CAssessment.Questions[i].Feedbacks[z].Text + "\n";
                    AXML += "</mattext>\n</material>\n</flow_mat>\n</itemfeedback>";
                    z++;
                }
                AXML += "</item>\n";
                i++;
            }

            AXML += "</section>\n</assessment>\n</questestinterop>";
            
            frames["iFile"].document.getElementById("hidGuid").value = Guid;
            frames["iFile"].document.getElementById("hidFolder").value = Resources[CurrentResource].Name;
            frames["iFile"].document.getElementById("hidXML").value = AXML;
            frames["iFile"].document.getElementById("hidFileName").value = "Assessment.xml";
            frames["iFile"].document.getElementById("btnMakeXMLFile").click();
            Resources[CurrentResource].Href = Resources[CurrentResource].Name + "/" + "Assessment.xml";
            Resources[CurrentResource].Files.push(Resources[CurrentResource].Name + "/" + "Assessment.xml");
            DisplayResources();
            //MakeXML();
        }
        
        function AddQuestion()
        {
            document.getElementById("AssessmentQuestionPanel").style.display = "block";
            CQuestion = new Question();
            CQuestionI = CAssessment.Questions.length;
            if (document.getElementById("ddlQuestionType").value == "cc.true_false.v0p1")
            {
                var ansT = new Answer();
                var ansF = new Answer();
                ansT.Text = "True";
                ansF.Text = "False";
                ansT.Score = 100;
                ansF.Score = 0;
                CQuestion.Answers.push(ansT);
                CQuestion.Answers.push(ansF);
                CAnswerI += 2;
                DisplayQuestionInfo();
            }
            SetGrayOut(1);
            FocusButons(4);
        }
        
        function CheckQuestionType(obj)
        {
            if (obj.value == "cc.true_false.v0p1")
            {
                CQuestion = new Question();
                var ansT = new Answer();
                var ansF = new Answer();
                ansT.Text = "True";
                ansF.Text = "False";
                ansT.Score = 100;
                ansF.Score = 0;
                CQuestion.Answers.push(ansT);
                CQuestion.Answers.push(ansF);
                CAnswerI += 2;
                DisplayQuestionInfo();
            }
        }
        
        function CreateQuestion(opt)
        {
            document.getElementById("AssessmentQuestionPanel").style.display = "none";
            
            SetGrayOut(0);
            if (opt == 0)
            {
                document.getElementById("RenderAnswers").innerHTML = "";
                document.getElementById("RenderFeedbacks").innerHTML = "";
                return;
            }

            var i = 0;
            var z = 0;
            while (i < CQuestion.Answers.length)
            {
                z = 0;
                while(z < CQuestion.Feedbacks.length)
                {
                    if (document.getElementById("cb-" + i + "-" + z).checked)
                        CQuestion.Answers[i].FRef.push("FID-" + z);
                    z++;
                }
                i++;
            }

            document.getElementById("RenderAnswers").innerHTML = "";
            document.getElementById("RenderFeedbacks").innerHTML = "";
            
            CQuestion.Title = document.getElementById("AssessmentQuestionTitle").value;
            CQuestion.Text = document.getElementById("AssessmentQuestionText").value;
            CQuestion.Type = document.getElementById("ddlQuestionType").value;
            CQuestion.TypeText = document.getElementById("ddlQuestionType").options[document.getElementById("ddlQuestionType").selectedIndex].text;
            CAssessment.Questions[CQuestionI] = CQuestion;
            DisplayAssessmentInfo();
        }
        
        function EditQuestion(Qid)
        {
            document.getElementById("AssessmentQuestionPanel").style.display = "block";
            CQuestion = CAssessment.Questions[Qid];
            CQuestionI = Qid;
            SetGrayOut(1);
            DisplayQuestionInfo();
        }
        
        function DeleteQuestion(Qid)
        {
            if (!confirm("Are you sure you want to delete this question?"))
                return;
            CQuestion.Answers.splice(Qid, 1);
            DisplayAssessmentInfo();
        }
        
        function AddAnswer()
        {
            document.getElementById("AnswerPanel").style.display = "block";
            document.getElementById("AnswerText").value = "";
            document.getElementById("cbCorrectAnswer").checked = false;
            CAnswer = new Answer();
            CAnswerI = CQuestion.Answers.length;
            SetGrayOut(2);
            FocusButons(5);
        }
        
        function CreateAnswer(opt)
        {
            document.getElementById("AnswerPanel").style.display = "none";
            
            SetGrayOut(1);
            if (opt == 0)
                return;

            CAnswer.Text = document.getElementById("AnswerText").value;
            if (document.getElementById("cbCorrectAnswer").checked)
                CAnswer.Score = 100;
            CQuestion.Answers[CAnswerI] = CAnswer;
            CAnswerI++;
            DisplayQuestionInfo();
        }
        
        function EditAnswer(Aid)
        {
            document.getElementById("AnswerPanel").style.display = "block";
            document.getElementById("AnswerText").value = CQuestion.Answers[Aid].Text;
            if (CQuestion.Answers[Aid].Score == 100)
                document.getElementById("cbCorrectAnswer").checked = true;
            else
                document.getElementById("cbCorrectAnswer").checked = false;
            CAnswer = new Answer();
            CAnswerI = Aid;
            SetGrayOut(2);
        }
        
        function DeleteAnswer(Aid)
        {
            if (!confirm("Are you sure you want to delete this answer?"))
                return;
            CQuestion.Answers.splice(Aid, 1);
            DisplayQuestionInfo();
        }
        
        function AddFeedback()
        {
            document.getElementById("FeedbackPanel").style.display = "block";
            document.getElementById("FeedbackText").value = "";
            CFeedback = new Feedback();
            CFeedbackI = CQuestion.Feedbacks.length;
            SetGrayOut(2);
            FocusButons(6);
        }
        
        function CreateFeedback(opt)
        {
            document.getElementById("FeedbackPanel").style.display = "none";
            
            SetGrayOut(1);
            if (opt == 0)
                return;

            CFeedback.Text = document.getElementById("FeedbackText").value;
            CQuestion.Feedbacks[CFeedbackI] = CFeedback;
            DisplayQuestionInfo();
        }

        function EditFeedback(Fid)
        {
            document.getElementById("FeedbackPanel").style.display = "block";
            document.getElementById("FeedbackText").value = CQuestion.Feedbacks[Fid].Text;
            CFeedback = new Answer();
            CFeedbackI = Fid;
            SetGrayOut(2);
        }

        function DeleteFeedback(Fid)
        {
            if (!confirm("Are you sure you want to delete this feeback?"))
                return;
            CQuestion.Feedbacks.splice(Fid, 1);
            DisplayQuestionInfo();
        }
        
        function DisplayAssessmentInfo()
        {
            var i = 0;
            document.getElementById("RenderQuestions").innerHTML = "";
            while(i < CAssessment.Questions.length)
            {
                document.getElementById("RenderQuestions").innerHTML += CAssessment.Questions[i].Title + ": " + CAssessment.Questions[i].Text + " - " + CAssessment.Questions[i].TypeText + " <input type='button' onclick='EditQuestion(" + i + ")' value='Edit Question'> <input type='button' onclick='DeleteQuestion(" + i + ")' value='Delete Question'><br>";
                i++;
            }
        }
        
        function DisplayQuestionInfo()
        {
            var i = 0;
            var z = 0;
            document.getElementById("RenderAnswers").innerHTML = "";
            while(i < CQuestion.Answers.length)
            {
                document.getElementById("RenderAnswers").innerHTML += CQuestion.Answers[i].Text + " - " + CQuestion.Answers[i].Score + " <input type='button' onclick='EditAnswer(" + i + ")' value='Edit Answer'> <input type='button' onclick='DeleteAnswer(" + i + ")' value='Delete Answer'><br>";
                z = 0;
                while (z < CQuestion.Feedbacks.length)
                {
                    document.getElementById("RenderAnswers").innerHTML += (z + 1) + ". <input type='checkbox' id='cb-" + i + "-" + z + "'>";
                    z++;
                }
                document.getElementById("RenderAnswers").innerHTML += "<br>";
                i++;
            }

            i = 0;
            document.getElementById("RenderFeedbacks").innerHTML = "";
            while(i < CQuestion.Feedbacks.length)
            {
                document.getElementById("RenderFeedbacks").innerHTML += (i + 1) + ". " + CQuestion.Feedbacks[i].Text + " <input type='button' onclick='EditFeedback(" + i + ")' value='Edit Feedback'> <input type='button' onclick='DeleteFeedback(" + i + ")' value='Delete Feedback'><br>";
                i++;
            }
        }

        function ChangeCourse(obj)
        {
            if (obj.selectedIndex == 0)
            {
                document.getElementById("txtLaunchURL").disabled = false;
                document.getElementById("txtToolID").disabled = false;
            }
            else
            {
                document.getElementById("txtLaunchURL").disabled = true;
                document.getElementById("txtToolID").disabled = true;
            }
        }
        
        function CreateLTI(opt)
        {
            SetGrayOut(-1);
            document.getElementById("LtiPanel").style.display = "none";
            if (opt == 0)
                return;

            var ltixml = "";
            var LaunchURL = "";
            var ToolID = "";

            if (document.getElementById("<%= ddlCourses.ClientID %>").value == "")
                ToolID = document.getElementById("txtToolID").value;
            else
                ToolID = document.getElementById("<%= ddlCourses.ClientID %>").value;

            if (document.getElementById("<%= ddlCourses.ClientID %>").value == "")
                LaunchURL = document.getElementById("txtLaunchURL").value;
            else
                LaunchURL = "<%= LTIEP %>";
            
            frames["iFile"].document.getElementById("hidGuid").value = Guid;
            frames["iFile"].document.getElementById("hidFolder").value = Resources[CurrentResource].Name;

            ltixml += "<cartridge_basiclti_link xmlns=\"http://www.imsglobal.org/xsd/imslticc_v1p0\" xmlns:blti=\"http://www.imsglobal.org/xsd/imsbasiclti_v1p0\" xmlns:lticm=\"http://www.imsglobal.org/xsd/imslticm_v1p0\" xmlns:lticp=\"http://www.imsglobal.org/xsd/imslticp_v1p0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.imsglobal.org/xsd/imslticc_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticc_v1p0p1.xsd http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0p1.xsd http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0p1.xsd http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0p1.xsd\">\n";
            ltixml += "<blti:title>" + document.getElementById("txtToolTitle").value + "</blti:title>\n";
            ltixml += "<blti:custom>\n";
            ltixml += "<blti:description></blti:description>";
            ltixml += "</blti:custom>\n";
            ltixml += "<blti:launch_url>" + LaunchURL + "</blti:launch_url>\n";
            ltixml += "<blti:vendor>\n";
            ltixml += "<lticp:code>www.mirlearn.com</lticp:code>\n";
            ltixml += "<lticp:name>" + document.getElementById("txtOrgTitle").value + "</lticp:name>\n";
            ltixml += "<lticp:description></lticp:description>\n";
            ltixml += "<lticp:url>" + document.getElementById("txtVendorUrl").value + "</lticp:url>\n";
            ltixml += "<lticp:contact>\n";
            ltixml += "<lticp:email>" + document.getElementById("txtVendorEmail").value + "</lticp:email>\n";
            ltixml += "</lticp:contact>\n";
            ltixml += "</blti:vendor>\n";
            ltixml += "</cartridge_basiclti_link>";

            frames["iFile"].document.getElementById("hidXML").value = ltixml;
            frames["iFile"].document.getElementById("hidFileName").value = "LTI.xml";
            frames["iFile"].document.getElementById("btnMakeXMLFile").click();
            Resources[CurrentResource].Href = Resources[CurrentResource].Name + "/" + "LTI.xml";
            Resources[CurrentResource].Files.push(Resources[CurrentResource].Name + "/" + "LTI.xml");
            DisplayResources();
            //MakeXML();
        }
        
        function SelectTable(opt)
        {
            document.getElementById("FolderTable").style.display = "none";
            document.getElementById("ResourceTable").style.display = "none";
            document.getElementById("BuildTable").style.display = "none";
            document.getElementById("FolderTab").style.backgroundColor = "#eeeeee";
            document.getElementById("ResourceTab").style.backgroundColor = "#eeeeee";
            document.getElementById("BuildTab").style.backgroundColor = "#eeeeee";
            
            if (opt == 1)
            {
                document.getElementById("FolderTable").style.display = "block";
                document.getElementById("FolderTab").style.backgroundColor = "#dddd00";
            }
            if(opt == 2)
            {
                document.getElementById("ResourceTable").style.display = "block";
                document.getElementById("ResourceTab").style.backgroundColor = "#dddd00";
                FocusButons(2);
            }
            if(opt == 3)
            {
                document.getElementById("BuildTable").style.display = "block";
                document.getElementById("BuildTab").style.backgroundColor = "#dddd00";
                MakeManifest();
            }
        }

        function SetGrayOut(lvl)
        {
            if (lvl >= 0)
            {
                document.getElementById("GrayOut").style.display = "block";
                document.getElementById("GrayOut").style.zIndex = lvl;
            }
            else
                document.getElementById("GrayOut").style.display = "none";
        }
        
        function FocusButons(opt)
        {
            if(opt == 2)
            {
                TryFocus("btnAddResource");
                TryFocus("btnDeleteResource");
                TryFocus("btnRenameResource");
                TryFocus("btnAddFile");
                TryFocus("btnSetHref");
            }
            if(opt == 3)
            {
                TryFocus("btnAddQuestion");
                TryFocus("btnCreateAssessment");
                TryFocus("btnCancelAssessment");
            }
            if(opt == 4)
            {
                TryFocus("btnAddAnswer");
                TryFocus("btnAddFeedback");
                TryFocus("btnCreateQuestion");
                TryFocus("btnCancelQuestion");
            }
            if(opt == 5)
            {
                TryFocus("btnAddAnswerDone");
                TryFocus("btnAddAnswerCancel");
            }
            if(opt == 6)
            {
                TryFocus("btnFeedbackDone");
                TryFocus("btnFeedbackCancel");
            }
            if(opt == 7)
            {
                TryFocus("btnCreateLTI");
                TryFocus("btnCancelLTI");
            }
        }
        
        function TryFocus(name)
        {
            try
            {
                document.getElementById(name).focus();
            }
            catch (err)
            {}
        }
        
        function ParseManifest()
        {
            if ("<%=CourseID %>" != "")
            {
                AuthWS.ParseFolders("<%= CourseID %>", ParseFoldersCallback);
                AuthWS.ParseResources("<%= CourseID %>", ParseResourcesCallBack);
            }    
        }
        
        function ParseFoldersCallback(Result)
        {
            Folders = Result;
            MakeTree();
        }
        
        function ParseResourcesCallBack(Result)
        {
            Resources = Result;
            DisplayResources();
        }
        
        function OpenHelpPopup()
        {
            document.getElementById("HelpPopup").style.display = "block";
        }
        
        function CloseHelpPopup()
        {
            document.getElementById("HelpPopup").style.display = "none";
        }
    </script>
</asp:Content>

